package com.typhoon.config;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/10 下午4:19
 * @description
 * @modified by
 * @since V2.0.0
 */

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

import javax.sql.DataSource;

/**
 * druid配置类
 *
 */
@Configuration
@PropertySource(factory = YamlPropertySourceFactory.class,value = "classpath:druid.yml")
@ConfigurationProperties(prefix = "spring.datasource")
public class DruidConfiguration {

    @Bean(destroyMethod = "close", initMethod = "init",name = "dataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }

//    @Bean
//    public static PropertySourcesPlaceholderConfigurer properties() {
//        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
//        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
//        yaml.setResources(new ClassPathResource("druid.yml"));
//        configurer.setProperties(yaml.getObject());
//        return configurer;
//    }
}